package com.dykj.fireFighting.web.controller.GB26875Controller;

import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.web.utils.OneNetUtils;
import org.apache.dubbo.common.utils.IOUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.quickserver.net.model.GBServerDataAll;
import org.quickserver.util.data.ReadShzcUtil;
import org.quickserver.util.data.dataProcessing;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

@Controller
@RequestMapping(value = "/shzc")
public class ShzcController {

    /**
     *
     * @param type  4消音   5复位
     * @param uniqueCode
     * @return
     */
    @RequestMapping(value = "/sengMsg",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult sengMsg(Integer type,String uniqueCode) {
        System.out.println("类型type-----"+type+"设备号----"+uniqueCode);
        Object obj = GBServerDataAll.handlerMap.get(uniqueCode);
        if(null != obj){
            Date date = new Date();
            String[] dates = dataProcessing.getDateTime16(date);
            String datesStr = "";

            for(int i = 0; i < dates.length; ++i) {
                datesStr = datesStr + dates[i];
            }
            if(type==4){
                return ReadShzcUtil.sendRead("0407020000"+datesStr,uniqueCode,date,type);
            }else if(type==5){
                return ReadShzcUtil.sendRead("0507020000"+datesStr,uniqueCode,date,type);
            }
            return CommonResult.success("命令下发成功");
        }else{
            return CommonResult.failed("连接错误,命令下发失败");
        }
    }
}
